package liu.de.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * @author liude
 */
@SuppressWarnings("WeakerAccess")
@Service
@Slf4j
public class RetryService {
    public static final int MAX_COUNT = 3;
    int counter = 0;

    @Retryable(maxAttempts = 2, backoff = @Backoff(delay = 1000))
    public void retry() throws Exception {
        counter++;
        log.info("retry, counter={}", counter);

        if (counter < MAX_COUNT) {
            throw new Exception("execute failed");
        }
    }
}
